package com.youngjun.user.service.impl;

import com.youngjun.user.mapper.RegionMapper;
import com.youngjun.user.pojo.domain.Region;
import com.youngjun.user.pojo.vo.RegionVO;
import com.youngjun.user.service.RegionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

@Service
public class RegionServiceImpl implements RegionService {

    @Autowired
    RegionMapper regionMapper;

    @Override
    public RegionMapper getMapper() {
        return regionMapper;
    }

    @Override
    public List<RegionVO> queryListByParentId(Long parentId) {
        return getMapper().queryListByParentId(parentId)
                .stream()
                .map(item->new RegionVO().mapFrom(item))
                .collect(Collectors.toList());
    }

    @Override
    public RegionVO queryById(Long id) {
        Region region = getMapper().select(new Region().setId(id));
        return new RegionVO().mapFrom(region);
    }

}
